<?php
namespace app\admin\controller;
use framework\ext\Check;

class DefaultController extends \app\base\controller\AdminController{
    
    //首页
	public function index(){
        $this->nav = model('nav')->top_select(array('pid' => 0));
		$this->display();
	}
	
    //欢迎
	public function welcome(){
        $this->userInfo = $_SESSION['admin_userInfo']; //用户信息;
        $this->group = model('auth')->find(array('id'=>$this->userInfo['groupid']));
		$this->display();
	}

    //信息通知
    public function news(){
        $this->display();
    }

	//菜单
    public function menu(){
        $nav = form('get.id',0,intval);
        $this->leftMenu = model('nav')->_select_lists($nav);
        $this->display();
    }

	//登录
	public function login(){
		if(!$this->isPost()){
			$this->display();
		}else{
            $username = form('post.username');
            $password = form('post.password');
            $msg = Check::rule(
                    array( Check::must($username), '请输入用户名') ,
                    array( Check::must($password), '请输入密码'));
            if(true !== $msg){
                $this->jsonMsg($msg);
            }
            $userInfo = model('admin')->getUserInfo($username);
            if($userInfo['lock'] == 1){
                $this->jsonMsg('您输入的用户被锁定已禁止登录');
            }
            $password = md5($password);
            if(!empty($userInfo) && $userInfo['password'] == $password){
                model('admin')->setUserInfo($userInfo['id']);
                $this->setLogin($userInfo);
                $this->jsonMsg('您输入的用户名或密码不正确',1,url('default/index'));
            }else{
                $this->jsonMsg('您输入的用户名或密码不正确');
            }
		}
	}
	
	//退出登录
	public function logout(){
		$this->clearLogin( url('default/login') );
	}

    //缓存管理
    public function cache(){
        $act = form('get.act');
        if($act == 'del'){
            $types = form('get.types');
            $result = model('themes')->delete_cache($types);
            if($result){
                $this->jsonMsg('删除成功',1);
            }else{
                $this->jsonMsg('删除失败');
            } 
        }else{
            $this->tpl_szie = model('themes')->cache_List('tpl');
            $this->log_szie = model('themes')->cache_List('log');
            $this->display();
        }
    }    
}